cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

project(recipe-02 LANGUAGES NONE)

find_package(PythonInterp REQUIRED)

set(_module_name "cffi")

execute_process(
        COMMAND ${PYTHON_EXECUTABLE} "-c" "import ${_module_name}; print(${_module_name}.__version__)"      # -command(c)
        OUTPUT_VARIABLE _stdout                                                             # 1.15.0
        ERROR_VARIABLE _stderr                                                              # 找不到输出 ModuleNotFoundError
        OUTPUT_STRIP_TRAILING_WHITESPACE
        ERROR_STRIP_TRAILING_WHITESPACE
)

if (_stderr MATCHES "ModuleNotFoundError")
    message(STATUS "Module ${_module_name} not found")
else ()
    message(STATUS "Found module ${_module_name} v${_stdout}")
endif ()